package coder.nav.model.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.regex.Pattern;

@Data
public class NavIdeRunOutErrVO implements Serializable {

    @ApiModelProperty("代码输出")
    private String stdout;

    @ApiModelProperty("代码运行错误信息")
    private String stderr;

    public String getContext() {
        String context = this.getStdout();
        if(StringUtils.isBlank(context) && StringUtils.isNotBlank(this.stderr)) {
            if(this.stderr.contains("./Main.java:") || Pattern.compile("PHP \\w+ error:").matcher(this.stderr).find()) {
                context = this.stderr;
            }
        }
        if(StringUtils.isNotBlank(context) && context.contains("coder-nav-not-print")) {
            context = this.stdout = this.stderr = ""; // 不打印结果
        }
        return context;
    }

}
